// #ifdef H5
let url = '/api' //需要配置跨域
// #endif

// #ifdef MP-WEIXIN
import {
	url
} from './config.js'
// #endif


function getvideourl(id) { //根据视频id获取播放地址
	return new Promise(function(resolve, reject) {
		uni.request({
			url: url + '/video/url',
			method: 'GET',
			data: {
				id
			},
			success: res => {
				resolve(res)
			}
		})
	})
}

function getvideo(cookie, offset, refresh) { //获取推荐视频  默认8个一条  设置动态page 算出offset可实现分页
	return new Promise(function(resolve, reject) {
		uni.request({
			url: url + '/video/timeline/recommend',
			method: 'GET',
			data: {
				cookie,
				offset,
				t: refresh ? Date.now() : 0 //刷新时增加时间戳避开缓存
			},
			success: res => {
				resolve(res)
			}
		})
	})
}

function userdetail(e) { //获取用户详情
	return new Promise(function(resolve, reject) {
		uni.request({
			url: url + '/user/detail',
			method: 'GET',
			data: {
				uid: e
			},
			success: res => {
				resolve(res)
			}
		})
	})
}

function account(e) { //获取账号信息
	return new Promise(function(resolve, reject) {
		uni.request({
			url: url + '/user/account',
			method: 'GET',
			success: res => {
				resolve(res)
			}
		})
	})
}

function validNumber(e) { //发送验证码
	return new Promise(function(resolve, reject) {
		uni.request({
			url: url + '/captcha/sent',
			method: 'GET',
			data: {
				phone: e
			},
			success: res => {
				resolve(res)
			}
		})
	})
}

function login(e) { //登录
	return new Promise(function(resolve, reject) {
		uni.request({
			url: url + '/login/cellphone',
			method: 'GET',
			data: {
				phone: e.phone,
				captcha: e.captcha
			},
			success: res => {
				resolve(res)
			}
		})
	})
}

function topList() { //首页
	return new Promise(function(resolve, reject) {
		uni.request({
			url: url + '/toplist/detail',
			method: 'GET',
			data: {},
			success: res => {
				resolve(res)
			},
			fail: () => {},
			complete: () => {}
		});
	})
}

function List(e) { //榜单详情
	return new Promise(function(resolve, reject) {
		uni.request({
			url: url + '/playlist/detail?id=' + e,
			method: 'GET',
			data: {},
			success: res => {
				resolve(res)
			},
			fail: () => {},
			complete: () => {}
		});
	})
}

function songDetail(e) { //歌曲详情
	return new Promise(function(resolve, reject) {
		uni.request({
			url: url + '/song/detail?ids=' + e,
			method: 'GET',
			data: {},
			success: res => {
				resolve(res)
			},
			fail: () => {},
			complete: () => {}
		});
	})
}

function simiSong(e) { //相似歌曲
	return new Promise(function(resolve, reject) {
		uni.request({
			url: url + '/simi/song?id=' + e,
			method: 'GET',
			success: res => {
				resolve(res)
			}
		});
	})
}

function comment(e) { //歌曲评论
	return new Promise(function(resolve, reject) {
		uni.request({
			url: url + '/comment/music?id=' + e,
			method: 'GET',
			success: res => {
				resolve(res)
			}
		});
	})
}

function lyric(e) { //歌词
	return new Promise(function(resolve, reject) {
		uni.request({
			url: url + '/lyric?id=' + e,
			method: 'GET',
			success: res => {
				resolve(res)
			}
		});
	})
}

function songUrl(e) { //歌曲资源
	return new Promise(function(resolve, reject) {
		uni.request({
			url: url + '/song/url?id=' + e,
			method: 'GET',
			success: res => {
				resolve(res)
			}
		});
	})
}

function searchHot() { //热搜排行榜
	return new Promise(function(resolve, reject) {
		uni.request({
			url: url + '/search/hot/detail',
			method: 'GET',
			success: res => {
				resolve(res)
			}
		});
	})
}

function inputRS(v, page = 1, type = 1, limit = 30, ) { //输入框搜索 带分页
	return new Promise(function(resolve, reject) {
		uni.request({
			url: url + '/search?keywords=' + v + '&type=' + type + '&limit=' + limit + '&offset=' + (page - 1) * 30,
			method: 'GET',
			success: res => {
				resolve(res)
			}
		});
	})
}

function searchTip(v) { //搜索提示框
	return new Promise(function(resolve, reject) {
		uni.request({
			url: url + '/search/suggest?keywords=' + v + '&type=mobile',
			method: 'GET',
			success: res => {
				resolve(res)
			}
		});
	})
}


export {
	topList,
	List,
	songDetail,
	simiSong,
	comment,
	lyric,
	songUrl,
	searchHot,
	inputRS,
	searchTip,
	validNumber,
	login,
	userdetail,
	account,
	getvideo,
	getvideourl
}
